package com.mhy.crash;

import android.app.Application;
import android.util.Log;

import com.mhy.crash.utils.CrashModel;
import com.mhy.crash.utils.HYCrashUtils;


public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        HYCrashLifecycle.getInstance().init(this);

        HYCrash.getInstance(this.getApplicationContext())
                .autoShowActivity(true)
                .autoKillApp(false)
                .setOnCrashListener(new HYCrash.OnCrashListener() {
                    @Override
                    public void onCrash(Thread t, Throwable ex) {
                        saveCrash(t, ex);
                    }
                });
    }

    private void saveCrash(Thread t, Throwable ex) {
        // 额外的功能 如果想自己保存
        CrashModel model = HYCrashUtils.parseCrash(this, ex);
        String text = HYCrashUtils.getShareText(this.getApplicationContext(), model);
        try {
            HYCrashUtils.saveTextToFile(this.getApplicationContext(), text);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

}
